<template>
  <view class="content">
    <image style="width: 100%;height: 1400rpx;" v-if="!is_show"  :src="info.image"></image>
	<video style="width: 100%;height: 1400rpx;" v-else autoplay="true" :src="info.video"></video>
  </view>

</template>

<script>
export default {
	data() {
		return {
			rewardedVideoAd:null,
			info:null,
			is_show:0
		};
	},
	onLoad(options) {
		var that = this
		var adIds = [
			100083012,
			100083013,
			100083014
		];
		var id = Math.floor(Math.random() * (2 - 0 + 1)) + 0;
		var adId = adIds[id];
		console.log(adId)
		that.rewardedVideoAd = ks.createRewardedVideoAd({		    type: 100011056,		    unitId: adId,		});
	    that.rewardedVideoAd.onLoad(() => {
			 // 激励视频广告已加载
	        console.log('onLoad event emit');
	    });
	    that.rewardedVideoAd.onError(({ errCode }) => {
			// 激励视频广告出错
	        console.log('onError event emit', errCode);
	    });
	    that.rewardedVideoAd.onClose(({ isEnded }) => {
			// that.showRewardedVideoAd();
	    });
		// that.showRewardedVideoAd();
		//更新
		uni.request({
		  // url: this.$host + 'api/news',
		  url: 'https://dy.anwuyouby.cn/api/v1/67db78ba379a3',
		  method:'post',
		  data: {id:1},
		  success: (result) => {
			  that.info = result.data.data
		    console.log(result)
		  },
		  fail: (err) => {
		    
		  },
		  complete: (e) => {
		    
		  }
		});
	},
	onShow() {
		ks.showShareMenu();
		var that = this
		uni.showModal({
			title:'提示',
			content:'点击观看视频',
			confirmText: '确定',
			confirmColor: '#3CC51F',
			cancelText: '取消',
			cancelColor: '#ccc',
			success: function (res) {
				if (res.confirm) {
					that.showRewardedVideoAd();
				} else if (res.cancel) {
					// that.showRewardedVideoAd();
				}
			}
		})
		
	},
	methods: {
		showRewardedVideoAd() {
			var that = this
		    that.rewardedVideoAd.show()
		        .catch(() => {
		            rewardedVideoAd.load()
		                .then(() => rewardedVideoAd.show())
		                .catch(err => {
		                    console.log('激励视频广告显示失败');
		                });
		        });
		},
	},
};
</script>

<style>
</style>